package com.itheima.test1;

public class MyThread extends Thread {

    static int ticket = 1000;

    @Override
    public void run() {
        while (true) {
            synchronized (MyThread.class) {
                if(ticket==0){
                    break;
                }else {
                    System.out.println(Thread.currentThread().getName()+"卖出一张票,剩余"+(--ticket)+"张");
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}
